package com.jmyd.coupon.server.service.impl;

import com.github.pagehelper.Page;
import com.github.pagehelper.page.PageMethod;
import com.jmyd.commons.base.service.impl.BaseServiceImpl;
import com.jmyd.commons.base.vo.PageBean;
import com.jmyd.coupon.server.domain.dto.SceneActivityDto;
import com.jmyd.coupon.server.domain.dto.SceneActivityQueryDto;
import com.jmyd.coupon.server.domain.po.SceneActivity;
import com.jmyd.coupon.server.domain.vo.SceneActivityVo;
import com.jmyd.coupon.server.mapper.SceneActivityMapper;
import com.jmyd.coupon.server.service.ISceneActivityService;
import org.springframework.stereotype.Service;
import tk.mybatis.mapper.entity.Example;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author samphin
 * @since 2021/7/15 10:03
 */
@Service
public class SceneActivityService extends BaseServiceImpl<Long, SceneActivityDto, SceneActivityVo> implements ISceneActivityService {

    @Resource
    private SceneActivityMapper sceneActivityMapper;

    @Override
    public boolean save(SceneActivityDto dto) {
        SceneActivity sceneActivity = new SceneActivity();
        return this.sceneActivityMapper.insertOrUpdate(sceneActivity) > 0;
    }

    @Override
    public boolean deleteById(Long id) {
        return this.sceneActivityMapper.deleteByPrimaryKey(id) > 0;
    }

    @Override
    public boolean deleteBatch(List<Long> ids) {
        Example example = new Example(SceneActivity.class);
        example.createCriteria().andIn("id", ids);
        return this.sceneActivityMapper.deleteByExample(example) > 0;
    }

    @Override
    public PageBean<SceneActivityVo> queryPageList(SceneActivityQueryDto queryDto) {
        Page<Object> page = PageMethod.startPage(queryDto.getPageNum(), queryDto.getPageSize());
        List<SceneActivity> poList = this.sceneActivityMapper.selectList(queryDto);
        List<SceneActivityVo> voList = new SceneActivityVo().buildVoList(poList);
        return new PageBean<>(voList, page);
    }

    @Override
    public SceneActivityVo queryById(Long id) {
        SceneActivity po = this.sceneActivityMapper.selectByPrimaryKey(id);
        return new SceneActivityVo().build(po);
    }
}
